<template>
  <a-card :bordered="false">


    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item :label="$t('order.orderNo')">
              <a-input :placeholder="$t('order.inputOrderNo')" v-model="queryParam.orderNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item :label="$t('order.posFactory')">
              <a-input :placeholder="$t('order.inputPosFactory')" v-model="queryParam.posFactory"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="8" :sm="24">
              <a-form-item :label="$t('order.status')">
              <j-dict-select-tag  v-model="queryParam.orderStatus" :placeholder="$t('order.inputOrderStatus')"
                                  dictCode="order_status"/>
            </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item :label="$t('order.type')">
              <j-dict-select-tag  v-model="queryParam.orderType" :placeholder="$t('order.inputOrderType')"
                                  dictCode="order_type"/>
            </a-form-item>
            </a-col>
            <a-col :md="16" :sm="24">
              <a-row :gutter="24">
                <a-col :md="24" :sm="24">
                  <span>{{$t('order.created')}}：</span>
                  <a-date-picker
                  style="width: 210px;"
                  showTime
                  format="YYYY-MM-DD HH:mm:ss"
                  @change="startTimeChange"
                  :placeholder="$t('common.chooseTime')"
                />-<a-date-picker
                  style="width: 210px;"
                  showTime
                  @change="endTimeChange"
                  format="YYYY-MM-DD HH:mm:ss"
                  value-format=" yyyy-MM-dd HH:mm:ss"
                  :placeholder="$t('common.chooseTime')"
                />
                </a-col>
              </a-row>
              
            </a-col>
          </template>
          <a-col :md="!advanced && 8 || 24" :sm="24">
            <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
              <a-button type="primary" @click="searchQuery" >{{$t('common.queryBtnTxt')}}</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">{{$t('common.resetBtnTxt')}}</a-button>
              <a @click="toggleAdvanced" style="margin-left: 8px">
                 {{ advanced ? $t('common.hideQueryBtnTxt') : $t('common.expQueryBtnTxt')  }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>


    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <a-button type="primary" icon="download" @click="handleExportXls($t('order.exportName'))">{{$t("common.expBtnTxt")}}</a-button>
      <!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>{{$t('common.delBtnTxt')}}</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> {{$t('common.batchOpBtnTxt')}} <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> {{$t('common.selectdTxt')}} <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>
        <a style="margin-left: 24px" @click="onClearSelected">{{$t('common.ckeanAllBtnTxt')}}</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="info(record)">{{$t('common.moreBtnTxt')}}</a>

          <!-- <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <order-modal ref="modalForm" @ok="modalFormOk"></order-modal>
  </a-card>
</template>

<script>
  import OrderModal from './modules/OrderModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'

  export default {
    name: "OrderList",
    mixins:[JeecgListMixin],
    components: {
      OrderModal
    },
    data () {
      return {
        // 高级搜索 展开/关闭
        advanced: true,
        description:  this.$t('order.sysName'),
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
		   {
            title: this.$t('order.mercharName'),
            key:'order.mercharName',
            align:"center",
            dataIndex: 'merchantId_dictText'
           },
		   {
            title: this.$t('order.equipmentId'),
             key:'order.equipmentId',
            align:"center",
            dataIndex: 'equipmentId_dictText'
           },
		   {
            title: this.$t('order.orderNo'),
             key:'order.orderNo',
            align:"center",
            dataIndex: 'orderNo'
           },
		   {
            title: this.$t('order.amountStr'),
             key:'order.amountStr',
            align:"center",
            dataIndex: 'amountStr'
           },
		   {
            title: this.$t('order.type'),
             key:'order.type',
            align:"center",
            dataIndex: 'type_dictText'
           },
		   {
            title: this.$t('order.status'),
             key:'order.status',
            align:"center",
            dataIndex: 'status_dictText'
           },
		   {
            title: this.$t('order.payDate'),
             key:'order.payDate',
            align:"center",
            dataIndex: 'payDate'
           },
		   {
            title: this.$t('order.posTradeNo'),
             key:'order.posTradeNo',
            align:"center",
            dataIndex: 'posTradeNo'
           },
          {
            title: this.$t('common.opBtnTxt'),
            key:'common.opBtnTxt',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          view: "/order/order/queryById",
          list: "/order/order/list",
          delete: "/order/order/delete",
          deleteBatch: "/order/order/deleteBatch",
          exportXlsUrl: "order/order/exportXls",
          importExcelUrl: "order/order/importExcel",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
     startTimeChange:function(value, dateString) {
        this.queryParam.startTime = dateString;
      },
      endTimeChange:function(value, dateString) {
        this.queryParam.endTime = dateString;
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      info:function(record){
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title= this.$t('common.detailBtnTxt');
        this.$refs.modalForm.disableSubmit = true;
      },
    },
     watch:{
        '$store.state.app.lang':function(newLang, oldLang){
          let that = this;
          this.columns.map(c => {
            if(c['key']) {
              c.title = that.$t(c.key)
            }
            console.log(c)
          })
        }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>